package com.yong.ssj.interceptor;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yong.ssj.db.dto.sys.UserDto;

public class LoginInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		
		String url = request.getServletPath();
		System.out.println(url);
		if("/admin/sys/login".equals(url) || "/admin/sys/login_do".equals(url)){
			System.out.println("-----用户登录页和用户登录处理可以放行-----");
			return true;
		} else {
			String user = (String) request.getSession().getAttribute("user");
			if(user==null){
				System.out.println("-----用户已登录，可以放行-----");
				request.getRequestDispatcher("/admin/sys/login").forward(request, response);
			}
		}
		System.out.println("-----preHandle-----");
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		System.out.println("-----postHandle-----");
	}

}
